using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Text;
using ECommerce.DAL;


namespace Entity
{
    /// <summary>
    /// This object represents the Private Fields of TblGiftCertificate.
    /// </summary>

    [System.ComponentModel.DataObject]
    public partial class TblGiftCertificate : DatabaseUtility
    {
        #region TblGiftCertificate Private Fields


        Int32 _giftCertificateId;
        String _code = String.Empty;
        String _fromEmailAddress = String.Empty;
        String _fromName = String.Empty;
        String _toEmailAddress = String.Empty;
        String _toName = String.Empty;
        String _message = String.Empty;
        Double _priceAmount;
        Double _currentBalance;
        DateTime _dateCreated;
        DateTime _dateExpired;
        Boolean _isActive;
        Boolean _isDeleted;
        Int32 _quantity;

        #endregion
        #region TblGiftCertificate Constractor
        /// <summary>
        /// Creates an empty object of TblGiftCertificate. 
        /// This is mainly used to create a new instance of TblGiftCertificate to add a new TblGiftCertificate.
        /// </summary>
        public TblGiftCertificate() { }


        /// <summary>
        /// Used to retrieve employee information from database, 
        /// which is also used by Update method to save information of an existing TblGiftCertificate.
        /// </summary>
        public TblGiftCertificate
        (
            Int32 giftCertificateId,
            String code,
            String fromEmailAddress,
            String fromName,
            String toEmailAddress,
            String toName,
            String message,
            Double priceAmount,
            Double currentBalance,
            DateTime dateCreated,
            DateTime dateExpired,
            Boolean isActive,
            Boolean isDeleted,
            Int32 quantity
        )
        {
            _giftCertificateId = giftCertificateId;
            _code = code;
            _fromEmailAddress = fromEmailAddress;
            _fromName = fromName;
            _toEmailAddress = toEmailAddress;
            _toName = toName;
            _message = message;
            _priceAmount = priceAmount;
            _currentBalance = currentBalance;
            _dateCreated = dateCreated;
            _dateExpired = dateExpired;
            _isActive = isActive;
            _isDeleted = isDeleted;
            _quantity = quantity;
        }

        #endregion
        #region TblGiftCertificate Properties

        /***********************************************************************************************
                                    -- PROPERTIES --        
         Contains all the properties representing the data fields of the current entity.
         ***********************************************************************************************/

        /// <summary>
        /// This is the Primary key value of the GiftCertificateId, which can't be assigned from the application,
        /// to ensure the data consistancy, by not letting the user to change the PK_TblGiftCertificate to update the data of an another TblGiftCertificate instance.
        /// For view or updation purpose, every TblGiftCertificate will be retrieved thru the proper 'Get' method.
        /// </summary>

        public Int32 GiftCertificateId
        {
            get { return _giftCertificateId; }
        }


        public String Code
        {
            get { return _code; }
            set { _code = value; }
        }

        public String FromEmailAddress
        {
            get { return _fromEmailAddress; }
            set { _fromEmailAddress = value; }
        }

        public String FromName
        {
            get { return _fromName; }
            set { _fromName = value; }
        }

        public String ToEmailAddress
        {
            get { return _toEmailAddress; }
            set { _toEmailAddress = value; }
        }

        public String ToName
        {
            get { return _toName; }
            set { _toName = value; }
        }

        public String Message
        {
            get { return _message; }
            set { _message = value; }
        }

        public Double PriceAmount
        {
            get { return _priceAmount; }
            set { _priceAmount = value; }
        }

        public Double CurrentBalance
        {
            get { return _currentBalance; }
            set { _currentBalance = value; }
        }

        public DateTime DateCreated
        {
            get { return _dateCreated; }
            set { _dateCreated = value; }
        }

        public DateTime DateExpired
        {
            get { return _dateExpired; }
            set { _dateExpired = value; }
        }

        public Boolean IsActive
        {
            get { return _isActive; }
            set { _isActive = value; }
        }

        public Boolean IsDeleted
        {
            get { return _isDeleted; }
            set { _isDeleted = value; }
        }

        public Int32 Quantity
        {
            get { return _quantity; }
            set { _quantity = value; }
        }


        #endregion
        #region TblGiftCertificate Static Methods
        /************************************************************************************
                                    -- CREATE METHOD (STATIC) --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public static Int32 CreateNewTblGiftCertificate
        (
            String code,
            String fromEmailAddress,
            String fromName,
            String toEmailAddress,
            String toName,
            String message,
            Double priceAmount,
            Double currentBalance,
            DateTime dateCreated,
            DateTime dateExpired,
            Boolean isActive,
            Boolean isDeleted,
            Int32 quantity
        )
        {
            //creating an empty TblGiftCertificate object
            TblGiftCertificate tblGiftCertificate = new TblGiftCertificate();
            tblGiftCertificate.Code = code;
            tblGiftCertificate.FromEmailAddress = fromEmailAddress;
            tblGiftCertificate.FromName = fromName;
            tblGiftCertificate.ToEmailAddress = toEmailAddress;
            tblGiftCertificate.ToName = toName;
            tblGiftCertificate.Message = message;
            tblGiftCertificate.PriceAmount = priceAmount;
            tblGiftCertificate.CurrentBalance = currentBalance;
            tblGiftCertificate.DateCreated = dateCreated;
            tblGiftCertificate.DateExpired = dateExpired;
            tblGiftCertificate.IsActive = isActive;
            tblGiftCertificate.IsDeleted = isDeleted;
            tblGiftCertificate.Quantity = quantity;

            return TblGiftCertificate.CreateNewTblGiftCertificate(tblGiftCertificate);
        }

        /************************************************************************************
                 -- UPDATE METHODS (STATIC) --
        *************************************************************************************/

        /************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        There the two types of paramaters will be passed here.
         * a. Primary key paramater: it should be Sql type, as we will bind the primary key property for the view controls (form view, details view etc) as datakey.
         * b. Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static bool UpdateTblGiftCertificate
        (
            Int32 giftCertificateId,
            String code,
            String fromEmailAddress,
            String fromName,
            String toEmailAddress,
            String toName,
            String message,
            Double priceAmount,
            Double currentBalance,
            DateTime dateCreated,
            DateTime dateExpired,
            Boolean isActive,
            Boolean isDeleted,
            Int32 quantity
        )
        {
            TblGiftCertificate tblGiftCertificate = TblGiftCertificate.GetTblGiftCertificateByGiftCertificateId(giftCertificateId);

            tblGiftCertificate.Code = code;
            tblGiftCertificate.FromEmailAddress = fromEmailAddress;
            tblGiftCertificate.FromName = fromName;
            tblGiftCertificate.ToEmailAddress = toEmailAddress;
            tblGiftCertificate.ToName = toName;
            tblGiftCertificate.Message = message;
            tblGiftCertificate.PriceAmount = priceAmount;
            tblGiftCertificate.CurrentBalance = currentBalance;
            tblGiftCertificate.DateCreated = dateCreated;
            tblGiftCertificate.DateExpired = dateExpired;
            tblGiftCertificate.IsActive = isActive;
            tblGiftCertificate.IsDeleted = isDeleted;
            tblGiftCertificate.Quantity = quantity;

            return TblGiftCertificate.UpdateTblGiftCertificate(tblGiftCertificate);
        }

        /************************************************************************************
                         -- DELETE METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        ****************************************************************************/
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static bool DeleteTblGiftCertificate
        (
            Int32 giftCertificateId
        )
        {
            //Validate Input
            if (giftCertificateId <= GetGiftCertificateIdMinValue)
                throw (new ArgumentOutOfRangeException("giftCertificateId"));

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddParameterToSqlCmd(sqlCmd, "@GiftCertificateId", SqlDbType.Int, 0, ParameterDirection.Input, giftCertificateId);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SPR_TBLGIFTCERTIFICATE_DELETETBLGIFTCERTIFICATE);
            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return (returnValue == 0 ? false : true);

        }

        /// <summary>
        /// Deletes a set of employees from the database.
        /// </summary>
        public static bool DeleteTblGiftCertificateList(System.Collections.Generic.List<Int32> giftCertificateIdListToDelete)
        {
            //Validate Input
            foreach (Int32 giftCertificateId in giftCertificateIdListToDelete)
                if (giftCertificateId <= GetGiftCertificateIdMinValue)
                    throw (new ArgumentOutOfRangeException("giftCertificateId"));

            //performing deletion operation //

            string xmlString = FormatXMLForIdArray(giftCertificateIdListToDelete);

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddParameterToSqlCmd(sqlCmd, "@GiftCertificateIdList", SqlDbType.Xml, xmlString.ToString().Length, ParameterDirection.Input, xmlString.ToString());
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SPR_TBLGIFTCERTIFICATE_DELETETBLGIFTCERTIFICATELIST);
            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return (returnValue == giftCertificateIdListToDelete.Count ? true : false);
        }

        /************************************************************************************
                                 -- GET BY PRIMARY METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        Retrives an Employee from database, based on it's primary key.
        To view or update an employee, everytime we must have to use this type of 'get' method, 
        since we don't have direct access to the Primary key value for assigning value.
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        /*****************************************************************************/
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static TblGiftCertificate GetTblGiftCertificateByGiftCertificateId(Int32 giftCertificateId)
        {
            if (giftCertificateId <= GetGiftCertificateIdMinValue)
                throw (new ArgumentOutOfRangeException("giftCertificateId"));

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@GiftCertificateId", SqlDbType.Int, 0, ParameterDirection.Input, giftCertificateId);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SPR_TBLGIFTCERTIFICATE_GETTBLGIFTCERTIFICATEBYGIFTCERTIFICATEID);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblGiftCertificateCollectionFromReader);
            CustomCollection<TblGiftCertificate> objCollection = ((CustomCollection<TblGiftCertificate>)ExecuteReaderCmd(sqlCmd, test));

            if (objCollection.Count > 0)
                return objCollection[0];
            else
                return null;
        }

        /************************************************************************************
                         -- GET BY FOREIGN KEY METHODS --
        *************************************************************************************/

        /************************************************************************************
                 -- GET ALL METHODS --
        *************************************************************************************/
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static CustomCollection<TblGiftCertificate> GetAllTblGiftCertificate()
        {

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SPR_TBLGIFTCERTIFICATE_GETALLTBLGIFTCERTIFICATE);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblGiftCertificateCollectionFromReader);
            CustomCollection<TblGiftCertificate> objCollection = ((CustomCollection<TblGiftCertificate>)ExecuteReaderCmd(sqlCmd, test));

            return objCollection;
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static CustomCollection<TblGiftCertificate> GetAllTblGiftCertificatePaged(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            //Validate Input
            if (orderBy == "")
                orderBy = "GiftCertificateId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRowIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, maximumRows);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SPR_TBLGIFTCERTIFICATE_GETALLTBLGIFTCERTIFICATEPAGED);

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblGiftCertificateCollectionFromReader);
            CustomCollection<TblGiftCertificate> objCollection = ((CustomCollection<TblGiftCertificate>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static int GetAllTblGiftCertificatePagedCount(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SPR_TBLGIFTCERTIFICATE_GETALLTBLGIFTCERTIFICATEPAGEDCOUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        #endregion
        #region Employee Instance Methods
        /************************************************************************************
                                    -- SAVE (INSERT/UPDATE) METHODS (INSTANCE) --
        *************************************************************************************/
        /// <summary>
        /// Saves (inserts and updates) an Employee into database.
        /// The insertion occur if the EmployeeId conatins default value.
        /// Otherwises it updates the Employee into the database, based on the primary key value stored in EmployeeId.
        /// This technique ensures an Employee will not be updated without having a valid EmployeeId.
        /// </summary>
        public bool Save()
        {
            if (GiftCertificateId <= GetGiftCertificateIdMinValue)
            {
                Int32 TempId = CreateNewTblGiftCertificate(this);
                if (TempId > 0)
                {
                    _giftCertificateId = TempId;
                    return true;
                }
                else
                {
                    // error occurs
                    return false;
                }
            }
            else
            {	//This is a update Command
                return (UpdateTblGiftCertificate(this));
            }

        }

        public static Int32 CreateNewTblGiftCertificate(TblGiftCertificate newTblGiftCertificate)
        {
            // validate Parameters
            if (newTblGiftCertificate == null)
                throw (new ArgumentNullException("newTblGiftCertificate"));

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            int length = 0;
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);

            AddParameterToSqlCmd(sqlCmd, "@Code", SqlDbType.NVarChar, 20, ParameterDirection.Input, newTblGiftCertificate.Code);
            AddParameterToSqlCmd(sqlCmd, "@FromEmailAddress", SqlDbType.NVarChar, 100, ParameterDirection.Input, newTblGiftCertificate.FromEmailAddress);
            AddParameterToSqlCmd(sqlCmd, "@FromName", SqlDbType.NVarChar, 100, ParameterDirection.Input, newTblGiftCertificate.FromName);
            AddParameterToSqlCmd(sqlCmd, "@ToEmailAddress", SqlDbType.NVarChar, 100, ParameterDirection.Input, newTblGiftCertificate.ToEmailAddress);
            AddParameterToSqlCmd(sqlCmd, "@ToName", SqlDbType.NVarChar, 100, ParameterDirection.Input, newTblGiftCertificate.ToName);
            AddParameterToSqlCmd(sqlCmd, "@Message", SqlDbType.NText, 0, ParameterDirection.Input, newTblGiftCertificate.Message);
            AddParameterToSqlCmd(sqlCmd, "@PriceAmount", SqlDbType.Float, 0, ParameterDirection.Input, newTblGiftCertificate.PriceAmount);
            AddParameterToSqlCmd(sqlCmd, "@CurrentBalance", SqlDbType.Float, 0, ParameterDirection.Input, newTblGiftCertificate.CurrentBalance);
            AddParameterToSqlCmd(sqlCmd, "@DateCreated", SqlDbType.DateTime, 0, ParameterDirection.Input, newTblGiftCertificate.DateCreated);
            AddParameterToSqlCmd(sqlCmd, "@DateExpired", SqlDbType.DateTime, 0, ParameterDirection.Input, newTblGiftCertificate.DateExpired);
            AddParameterToSqlCmd(sqlCmd, "@IsActive", SqlDbType.Bit, 0, ParameterDirection.Input, newTblGiftCertificate.IsActive);
            AddParameterToSqlCmd(sqlCmd, "@IsDeleted", SqlDbType.Bit, 0, ParameterDirection.Input, newTblGiftCertificate.IsDeleted);
            AddParameterToSqlCmd(sqlCmd, "@Quantity", SqlDbType.Int, 0, ParameterDirection.Input, newTblGiftCertificate.Quantity);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SPR_TBLGIFTCERTIFICATE_CREATENEWTBLGIFTCERTIFICATE);
            ExecuteScalarCmd(sqlCmd);
            return (Int32.Parse(sqlCmd.Parameters["@ReturnValue"].Value.ToString()));

        }
        /// <summary>
        /// Updates an TblGiftCertificate instance to the database.
        /// </summary>
        public static bool UpdateTblGiftCertificate(TblGiftCertificate newTblGiftCertificate)
        {
            // validate Parameters
            if (newTblGiftCertificate == null)
                throw (new ArgumentNullException("newTblGiftCertificate"));

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            int length = 0;
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);

            AddParameterToSqlCmd(sqlCmd, "@GiftCertificateId", SqlDbType.Int, 0, ParameterDirection.Input, newTblGiftCertificate.GiftCertificateId);
            AddParameterToSqlCmd(sqlCmd, "@Code", SqlDbType.NVarChar, 20, ParameterDirection.Input, newTblGiftCertificate.Code);
            AddParameterToSqlCmd(sqlCmd, "@FromEmailAddress", SqlDbType.NVarChar, 100, ParameterDirection.Input, newTblGiftCertificate.FromEmailAddress);
            AddParameterToSqlCmd(sqlCmd, "@FromName", SqlDbType.NVarChar, 100, ParameterDirection.Input, newTblGiftCertificate.FromName);
            AddParameterToSqlCmd(sqlCmd, "@ToEmailAddress", SqlDbType.NVarChar, 100, ParameterDirection.Input, newTblGiftCertificate.ToEmailAddress);
            AddParameterToSqlCmd(sqlCmd, "@ToName", SqlDbType.NVarChar, 100, ParameterDirection.Input, newTblGiftCertificate.ToName);
            AddParameterToSqlCmd(sqlCmd, "@Message", SqlDbType.NText, 0, ParameterDirection.Input, newTblGiftCertificate.Message);
            AddParameterToSqlCmd(sqlCmd, "@PriceAmount", SqlDbType.Float, 0, ParameterDirection.Input, newTblGiftCertificate.PriceAmount);
            AddParameterToSqlCmd(sqlCmd, "@CurrentBalance", SqlDbType.Float, 0, ParameterDirection.Input, newTblGiftCertificate.CurrentBalance);
            AddParameterToSqlCmd(sqlCmd, "@DateCreated", SqlDbType.DateTime, 0, ParameterDirection.Input, newTblGiftCertificate.DateCreated);
            AddParameterToSqlCmd(sqlCmd, "@DateExpired", SqlDbType.DateTime, 0, ParameterDirection.Input, newTblGiftCertificate.DateExpired);
            AddParameterToSqlCmd(sqlCmd, "@IsActive", SqlDbType.Bit, 0, ParameterDirection.Input, newTblGiftCertificate.IsActive);
            AddParameterToSqlCmd(sqlCmd, "@IsDeleted", SqlDbType.Bit, 0, ParameterDirection.Input, newTblGiftCertificate.IsDeleted);
            AddParameterToSqlCmd(sqlCmd, "@Quantity", SqlDbType.Int, 0, ParameterDirection.Input, newTblGiftCertificate.Quantity);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SPR_TBLGIFTCERTIFICATE_UPDATETBLGIFTCERTIFICATE);
            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return (returnValue == 0 ? false : true);
        }
        #endregion

        #region TblGiftCertificate Related Collections
        /// <summary>
        /// Creates and returns a strongly typed collection of Employee custom entity. 
        /// The colelction is created through iterating on the IdataReader object which contains Employee information, as a set of records, similar to tabular format.
        /// </summary>
        public static CollectionBase GenerateTblGiftCertificateCollectionFromReader(IDataReader returnData)
        {

            //creating the instance of Employee collection
            CustomCollection<TblGiftCertificate> colTblGiftCertificate = new CustomCollection<TblGiftCertificate>();

            /************************* Architecure note:**********************************
             * Below code includes the null value functionality to retieve the data which has nill value in database end.
             * Design consideration:
             * Besides general data fields, special care should be taken for primary keys, to assign '0'/defaultvalue, rather passing 'Null' value in constructor parameter.
             * Although we are considering sqldb tyoe data for the current data container, but while retireving data from database end, through datareader object, we need to cast data reader objects using .net primitive data type, 
             * rather using sqldb type to cast, since data reader objects don't support sql db type to be casted.
             *****************************************************************************/

            //Iterating thriugh the data reader, to generate Employee collection.

            //getting the Employee collection by iterating thru the data reader
            while (returnData.Read())
            {
                //passing the TblGiftCertificate constructor parameters from the current instance of data reader fields.
                TblGiftCertificate newTblGiftCertificate = new TblGiftCertificate
                (
                    returnData["GiftCertificateId"] == System.DBNull.Value ? GetGiftCertificateIdMinValue : (Int32)returnData["GiftCertificateId"],
                    returnData["Code"] == System.DBNull.Value ? string.Empty : (String)returnData["Code"],
                    returnData["FromEmailAddress"] == System.DBNull.Value ? string.Empty : (String)returnData["FromEmailAddress"],
                    returnData["FromName"] == System.DBNull.Value ? string.Empty : (String)returnData["FromName"],
                    returnData["ToEmailAddress"] == System.DBNull.Value ? string.Empty : (String)returnData["ToEmailAddress"],
                    returnData["ToName"] == System.DBNull.Value ? string.Empty : (String)returnData["ToName"],
                    returnData["Message"] == System.DBNull.Value ? null : (String)returnData["Message"],
                    returnData["PriceAmount"] == System.DBNull.Value ? 0 : (Double)returnData["PriceAmount"],
                    returnData["CurrentBalance"] == System.DBNull.Value ? 0 : (Double)returnData["CurrentBalance"],
                    returnData["DateCreated"] == System.DBNull.Value ? DateTime.MinValue : (DateTime)returnData["DateCreated"],
                    returnData["DateExpired"] == System.DBNull.Value ? DateTime.MinValue : (DateTime)returnData["DateExpired"],
                    returnData["IsActive"] == System.DBNull.Value ? false : (Boolean)returnData["IsActive"],
                    returnData["IsDeleted"] == System.DBNull.Value ? false : (Boolean)returnData["IsDeleted"],
                    returnData["Quantity"] == System.DBNull.Value ? 0 : (Int32)returnData["Quantity"]

                );
                //adding the Employee to the collection
                colTblGiftCertificate.Add(newTblGiftCertificate);
            }

            //returns the collection of Companys 
            return (colTblGiftCertificate);
        }

        #endregion
        #region Constants and Default Values

        public static Int32 GetGiftCertificateIdMinValue
        {
            get
            {
                return 0;
            }
        }

        //create method related contants
        internal const string SPR_TBLGIFTCERTIFICATE_CREATENEWTBLGIFTCERTIFICATE = "spr_TblGiftCertificate_CreateNewTblGiftCertificate";
        internal const string SPR_TBLGIFTCERTIFICATE_UPDATETBLGIFTCERTIFICATE = "spr_TblGiftCertificate_UpdateTblGiftCertificate";
        internal const string SPR_TBLGIFTCERTIFICATE_DELETETBLGIFTCERTIFICATE = "spr_TblGiftCertificate_DeleteTblGiftCertificate";
        internal const string SPR_TBLGIFTCERTIFICATE_DELETETBLGIFTCERTIFICATELIST = "spr_TblGiftCertificate_DeleteTblGiftCertificateList";
        internal const string SPR_TBLGIFTCERTIFICATE_GETTBLGIFTCERTIFICATEBYGIFTCERTIFICATEID = "spr_TblGiftCertificate_GetTblGiftCertificateByGiftCertificateId";
        internal const string SPR_TBLGIFTCERTIFICATE_GETALLTBLGIFTCERTIFICATE = "spr_TblGiftCertificate_GetAllTblGiftCertificate";
        internal const string SPR_TBLGIFTCERTIFICATE_GETALLTBLGIFTCERTIFICATEPAGED = "spr_TblGiftCertificate_GetAllTblGiftCertificatePaged";
        internal const string SPR_TBLGIFTCERTIFICATE_GETALLTBLGIFTCERTIFICATEPAGEDCOUNT = "spr_TblGiftCertificate_GetAllTblGiftCertificatePagedCount";

        #endregion
    }
}